﻿@model Nop.Web.Models.Catalog.ProductOverviewModel
@using Nop.Core.Infrastructure;
@{
    bool ajaxCartEnabledOnCatalogPages = false;

    var electronicsThemeSettings = EngineContext.Current.Resolve<SevenSpikes.Theme.Electronics.Domain.ElectronicsThemePluginsIntegrationSettings>();

    var ajaxCartIntegrated = electronicsThemeSettings.IntegrateNopAjaxCart;

    if (ajaxCartIntegrated)
    {
        var nopAjaxCartSettings = EngineContext.Current.Resolve<SevenSpikes.Nop.Plugins.AjaxCart.Domain.NopAjaxCartSettings>();
        if (nopAjaxCartSettings != null)
        {
            ajaxCartEnabledOnCatalogPages = nopAjaxCartSettings.EnableOnCatalogPages;
        }
    }

    //prepare "Add to cart" AJAX link
    string addtocartlink = "";
    if (Model.ProductPrice.ForceRedirectionAfterAddingToCart)
    {
        addtocartlink = Url.RouteUrl("AddProductToCart", new { productId = Model.Id, forceredirection = Model.ProductPrice.ForceRedirectionAfterAddingToCart });
    }
    else
    {
        addtocartlink = Url.RouteUrl("AddProductToCart", new { productId = Model.Id });
    }    
}
<div class="item">
    <div class="picture">
        <a href="@Url.RouteUrl("Product", new { productId = Model.Id, SeName = Model.SeName })" title="@Model.DefaultPictureModel.Title">
            <img style="border-width: 0px;" alt="@Model.DefaultPictureModel.AlternateText" src="@Model.DefaultPictureModel.ImageUrl"
                                                        title="@Model.DefaultPictureModel.Title" /></a>
    </div>
    <div class="product-title">
        <a href="@Url.RouteUrl("Product", new { productId = Model.Id, SeName = Model.SeName })" title="@Model.DefaultPictureModel.Title">
            @Model.Name</a>
    </div>
    <div class="prices">
        @if (!String.IsNullOrEmpty(Model.ProductPrice.OldPrice))
        {
            <span class="oldproductPrice">@Model.ProductPrice.OldPrice</span>
            <br />
        }
        <span class="productPrice">@Model.ProductPrice.Price</span>
    </div>
    <div class="buttons-centered">
        @if (!Model.ProductPrice.DisableBuyButton)
        {
            if (ajaxCartIntegrated && ajaxCartEnabledOnCatalogPages)
            {
            @Html.Action("GetAddProductToCartAjaxButton", "NopAjaxCart", new { ProductId = Model.Id, ButtonValue = Model.ProductPrice.AvailableForPreOrder ? T("ShoppingCart.PreOrder") : T("ShoppingCart.AddToCart") })
            }
            else
            {
            <input type="button" value="@(Model.ProductPrice.AvailableForPreOrder ? T("ShoppingCart.PreOrder") : T("ShoppingCart.AddToCart"))" class="productlistaddtocartbutton" onclick="AjaxCart.addproducttocart('@addtocartlink');return false;" />
            }
        }
        @Html.Action("WidgetsByZone", "Widget", new { widgetZone = "productbox_add_info" })
    </div>
</div>
